package com.gin.kotlin.gf2gamecommunity.base.util

import android.database.Cursor
import android.provider.MediaStore
import java.io.File

/**
 * 从URI中读取文件信息
 * @param cursor [Cursor]
 * @constructor
 */
class ContentFileInfo(cursor: Cursor) {
    val originalName: String? = cursor.readStringOrNull(MediaStore.Files.FileColumns.DISPLAY_NAME)
    val size: Int? = cursor.readStringOrNull(MediaStore.Files.FileColumns.SIZE)?.toIntOrNull()
    val mimeType: String? = cursor.readStringOrNull(MediaStore.Files.FileColumns.MIME_TYPE)
    val ext: String? = originalName?.let { File(it).extension } ?: this.mimeType?.split("/")?.get(1)
}